package com.xxx.controller;


import com.xxx.entity.Users;
import com.xxx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class AdminLoginController {


    @Autowired
    private UserService userService;


    @RequestMapping("/admin/login/show")
    public String adminLoginShow(){
        return "/admin/login";
    }


    @RequestMapping("/admin/login/submit")
    public String adminLoginSubmit(Users users, Model model, HttpSession session){
        Users adminUser = userService.adminLogin(users);

        // 判断登录的账号是否存在
        if (adminUser == null){
            model.addAttribute("error","用户名或密码错误！");
            return "/admin/login";
        }

        // 将登录的对象存入session，用于会话跟踪管理
        //model.addAttribute("adminUser",adminUser);
        session.setAttribute("adminUser",adminUser);
        return "/admin/index";
    }

}
